
<?php

defined('BASEPATH') or die('forbidden');
//登陆异常跟踪
class fenxiReport_Controller Extends Controller {
	
	private $dbName;	//数据库名
	private $eventTypeList;	//事件列表
	private $reportGraph;	//传给图表的数据
	
    function _init() {
        check_level(50, segment(0), segment(1));
        require_once(CONFIGPATH . 'inc.php');
        
        $this->db->select_db("crashreport");
    	//$this->db->select_db("buglist");	//for test

    	$sql = "SELECT *  FROM eventtype ";
        $this->db->query($sql);
        $eventTypeList = array();	//事件列表
    	while ($n = $this->db->get_array('default')) 
    	{
   			$this->eventTypeList[$n['eventID']] = $n['eventValue'];
        } 
    	//print_r($eventTypeList);
    }

    function index() {
        $this->view->display("message/fenxiReport/index");
    }
    
	function flexigrid() 
	{
		 
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			
		$sql = "SELECT COUNT(*) AS num FROM ".$this->dbName.".analysereport	 WHERE {$where} ";
		//echo " sql2:$sql ";
		$one = $this->db->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		 
		$sql = "SELECT {$colsinfo} FROM ".$this->dbName.".analysereport  WHERE {$where}  {$orderby} LIMIT {$offset},{$rp}";
		$this->db->query($sql);
		//$id = 0;
		while ($n = $this->db->get_array('default'))
		{			
			$rows[] = array('id' => $n['id'], 'cell' => $n);
			
			foreach ($n as $key=>$value)
			{
				/*
				if ($key == 'inserttime') {	//特殊情况
					$this->reportGraph[$n['id']][$key] = $key;
				}else 
				{
					$this->reportGraph[$n['id']][$key] += $value;
				}
				*/
				$this->reportGraph[$n['id']][$key] += $value;
			}
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		 
		echo json_encode($result);
		$this->view->assign("reportGraph",$this->reportGraph);
	}    
    

}